package com.xiaodou.mjf.application.content.service.impl;

import java.util.List;

import com.xiaodou.mjf.application.content.repository.AdvertRepository;
import com.xiaodou.mjf.application.content.service.AdvertService;
import com.xiaodou.mjf.entity.content.Advert;
import com.xiaodou.mjf.infrastructure.common.app.JpaSimpleService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import javax.transaction.Transactional;


/***
 *
 * Advert业务访问实现
 * @author XiaoDou.com Code Generator
 * @version 1.0
 * 2014-10-29 17:37:52
 *
 */
@Service @Transactional
public class AdvertServiceImpl extends JpaSimpleService<Advert,String> implements AdvertService{

	Logger logger = LoggerFactory.getLogger(AdvertServiceImpl.class);

    @Resource
    AdvertRepository advertRepository;

    @Override
    protected JpaRepository<Advert, String> getRepository() {
        return advertRepository;
    }

	@Override
	public List<Advert> findByfinanceId(String finacingId) {
		List<Advert> adverts = advertRepository.findAll((root, query, cb) -> {
			Predicate p1 = cb.equal(root.get("financingId").as(String.class),
					finacingId);
			return query.where(p1).getRestriction();

		});

		return adverts;
	}
}

